package java_class_work.week08.internet.castUpper;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author Tiam
 * @Date 2022/11/1 11:09
 * @Description:
 */
public class Server {
    public static void main(String[] args) {
        try {

            ServerSocket serverSocket = new ServerSocket(8888);
            Socket socket = serverSocket.accept();

            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            // BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
            while (true) {
                String receive = in.readLine();
                System.out.println("对方给你发送的消息:" + receive);
                if ("stop".equalsIgnoreCase(receive)) break;

                // 转换为大写后返回

                // 打印流 PrintWriter
                out.println(receive.toUpperCase());

                // 缓冲流BufferedWriter, 需要接收换行 刷新
                /*
                out.write(receive.toUpperCase());
                out.newLine();
                out.flush();
                */
            }
            socket.close();
            serverSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
